home *** CD-ROM | disk | FTP | other *** search
/ Utilities Professional 1-1500 / Utilities Professional 1-1500 (1994)(WPD)[!].iso / 12511500 / var1286.dms / var1286.adf / printers / IBMColorJet / Render.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  8KB  |  218 lines

  1. /* IBM ColourJet */
  2. /* ColourJet/Render.c */
  3. /*
  4.     The IBM ColourJet will only allow the printing of multiple colour per
  5.     line in the multicolour raster image mode.  This mode requires Red,
  6.     Green, and Blue colour inputs.  Therefore as the colour class of BGRW
  7.     is only supported under 1.2, version 1.2 is required and incorrect
  8.     colours will be produced under 1.1.
  9.  
  10.     If any changes or improvements are made to this driver I would
  11.     appreciate hearing of these.
  12.  
  13.     Michael Galway
  14.     28 Cramer Drive
  15.     Nepean, Ontario, CANADA
  16.     K2H 5X5
  17. */
  18. /*****************************************************************************/
  19. #include  "exec/types.h"
  20. #include  "exec/nodes.h"
  21. #include  "exec/lists.h"
  22. #include  "exec/memory.h"
  23. #include  "devices/printer.h"
  24. #include  "devices/prtbase.h"
  25.  
  26. extern struct PrinterData *PD;
  27. extern struct PrinterExtendedData *PED;
  28.  
  29. int Render(ct, x, y, status)
  30.  
  31. UBYTE ct;       /* colour type - null for b/w printers */
  32. UWORD x, y;     /* the x & y co-ordinates              */
  33. UBYTE status;   /* print status                        */
  34.  
  35. /*  colour type values
  36.                              Colour Class
  37.  
  38.                         CT   BGRW    YMCB
  39.                         ==   ====    ====
  40.  
  41.                          0 - White  (Black)
  42.                          1 - Blue   (Yellow)
  43.                          2 - Green  (Magenta)
  44.                          3 - Red    (Cyan)
  45.  
  46.  
  47.     status values        0 - master initialization / allocate buffer memory
  48.                          1 - render pixel into buffer
  49.                          2 - dump buffer to printer
  50.                          3 - clear and initialize buffer
  51.                          4 - close down and de-allocate buffer memory
  52.                          5 - density selection
  53. */
  54. {
  55.     static UWORD ROWSIZE, COLORSIZE, COLORBUFFER, BUFSIZE, bufptr, colors[4];
  56.     static UWORD offsetpixels, offsetbytes, pixeloffset, allwhite;
  57.     static UBYTE R, G, B, W, red, green, blue, imageoffset;
  58.  
  59.     /* set multi-colour raster image mode and horiz. vert. resolution */
  60.     static UBYTE graphicsinit[] ={27, 91, 79, 0,  0,   128, 31, 0, 100, 0};
  61.                                /* ESC [   O   Low High Multicolor  HR   VR    */
  62.  
  63.     static UBYTE setresolution[] ={27, 91, 48, 1, 0, 0};
  64.                                 /* ESC [   0   1  0  0 */
  65.  
  66.     static UBYTE advanceline[] ={27, 91, 85, 1, 0, 1, 13};
  67.                               /* ESC [   U   1  0  1  CR */
  68.  
  69.     static UBYTE bitvalues[]={128, 64, 32, 16, 8, 4, 2, 1};
  70.  
  71.     static UBYTE  center, lpi, resolution;
  72.     static UBYTE  imagepad, Pad, PadValue;
  73.     UBYTE bitnum;
  74.     UWORD i, j, bytenum;
  75.     int err;
  76.  
  77.     switch(status)  {
  78.     case 0 :          /* alloc memory for printer buffer */
  79.      /* use preferences DRAFT/LETTER quality setting for 72/96 lines/inch    */
  80.      graphicsinit[9]=lpi;
  81.      if (lpi=72)
  82.        resolution=1;
  83.      else
  84.        resolution=3;
  85.      setresolution[5]=resolution;
  86.      W=0; B=1; G=2; R=3; red=0; green=1; blue=2;
  87.  
  88.      /* # of centering pixels */
  89.      offsetpixels = (center) ? ((PED->ped_MaxXDots - x) / 2) : 0;
  90.      offsetbytes  = offsetpixels >> 3;
  91.      pixeloffset  = offsetpixels - offsetbytes * 8;
  92.      imagepad     = !((1 << (8-pixeloffset)) - 1);
  93.      /* compute buffer size */
  94.      ROWSIZE=x + offsetpixels;     /* pixels per line */
  95.      imageoffset=10;               /* set colour raster images printing mode */
  96.      COLORSIZE=(ROWSIZE + 7) >> 3; /* size of a colour buffer in bytes       */
  97.      COLORBUFFER=COLORSIZE * 3;    /* size of RGB colour buffers in bytes    */
  98.      BUFSIZE=COLORBUFFER +imageoffset +1;  /* move down 1 line               */
  99.      Pad=COLORSIZE *8 - x - offsetpixels;  /* padding for # of pixels to be  */
  100.                                            /* integer bytes                  */
  101.      PadValue=0;
  102.      if (Pad != 0) PadValue= (1 << Pad) - 1;  /* 2^Pad -1 */
  103.  
  104.      /* store graphics buffer size for later printer initialization          */
  105.      graphicsinit[3] = (COLORBUFFER + 5) & 0xff; /* Low  Count of data bytes */
  106.      graphicsinit[4] = (COLORBUFFER + 5) >> 8;   /* High Count of data bytes */
  107.  
  108.      /* compute where to put pixel data in each colour buffer                */
  109.      colors[R]=COLORSIZE* red   +imageoffset +offsetbytes;
  110.      colors[G]=COLORSIZE* green +imageoffset +offsetbytes;
  111.      colors[B]=COLORSIZE* blue  +imageoffset +offsetbytes;
  112.  
  113.                                 
  114.      /* allocate buffer memory, double buffering = 2*BUFSIZE */
  115.      PD->pd_PrintBuf = (UBYTE *) AllocMem(BUFSIZE*2,MEMF_PUBLIC);
  116.  
  117.      if (err=(PD->pd_PrintBuf == 0)) return(err);
  118.  
  119.      /* set printer to beginning of line and empty buffer */
  120.      if (err=(*(PD->pd_PWrite))("\030\015",2)) return(err); /* CTRL-X, CR    */
  121.      if (err=PWait(1,0)) return(err);
  122.  
  123.      /* set resolution to 72 or 96 lpi for skipping over white lines */
  124.      if (err=(*(PD->pd_PWrite))(&setresolution,6)) return(err);
  125.      return(err);
  126.  
  127.      bufptr=0;
  128.      return(0); /* flag all ok */
  129.      break;
  130.  
  131.     case 1 :   /* put pixel in buffer */
  132.      /* White == Red=Green=Blue=1 */
  133.      bytenum=(x + pixeloffset) >> 3;    /* (x+pixeloffset)/8 */
  134.      bitnum =(x + pixeloffset) & 7;     /* (x+pixeloffset)%8 */
  135.      if (ct==0) {
  136.        i = bufptr+colors[R]+bytenum;    /* calc which byte to use for red    */
  137.        PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
  138.  
  139.        i = bufptr+colors[G]+bytenum;    /* calc which byte to use for green  */
  140.        PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
  141.  
  142.        i = bufptr+colors[B]+bytenum;    /* calc which byte to use for blue   */
  143.        PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
  144.        allwhite++;
  145.      }
  146.      else {
  147.        i = bufptr+colors[ct]+bytenum;   /* calc byte to use for colour==ct   */
  148.        PD->pd_PrintBuf[i] = PD->pd_PrintBuf[i] | bitvalues[bitnum];
  149.      }
  150.      return(0);
  151.      break;
  152.  
  153.     case 2 :   /* common dump buffer to printer */
  154.      if (allwhite != ROWSIZE) {
  155.        if (err=(*(PD->pd_PWrite))(&(PD->pd_PrintBuf[bufptr]), BUFSIZE))
  156.          return(err);
  157.        bufptr=BUFSIZE-bufptr;     /* bufptr alternates between 0 and BUFSIZE */
  158.      }
  159.      else
  160.        if (err=(*(PD->pd_PWrite))(&advanceline,7)) return(err);
  161.      return(err);
  162.      break;
  163.  
  164.     case 3 :   /* clear and init buffer */
  165.      /* set buffer to black */
  166.      for (i=bufptr; i<bufptr+BUFSIZE; i++)  PD->pd_PrintBuf[i] = 0;
  167.  
  168.      /* pad from left to start of image with white */
  169.      for (j=0; j<3; j++)  {
  170.        for (i=0; i<offsetbytes; i++)
  171.          PD->pd_PrintBuf[bufptr+COLORSIZE*j+imageoffset+i]=255;
  172.        PD->pd_PrintBuf[bufptr+COLORSIZE*j+imageoffset+offsetbytes]=imagepad;
  173.      }
  174.  
  175.      /* pad unused bit positions in last byte with white */
  176.      for (i=1; i<4; i++)
  177.        PD->pd_PrintBuf[bufptr+COLORSIZE*i+imageoffset-1]= PadValue;
  178.  
  179.      /* store graphics control codes at beginning of buffer */
  180.      for (i=0; i<10; i++)  PD->pd_PrintBuf[bufptr+i] = graphicsinit[i];
  181.  
  182.      /* put advance line cammand at end of buffer */
  183.      PD->pd_PrintBuf[bufptr+BUFSIZE-1]=13;
  184.  
  185.      /* assume line not all white, therefore print normally */
  186.      allwhite=0;
  187.  
  188.      return(0);
  189.      break;
  190.  
  191.     case 4 :   /* common free the print buffer memory and exit */
  192.      err=(*(PD->pd_PWrite))("\015",1);       /* carriage return              */
  193.      if (!err) err=(*(PD->pd_PBothReady))(); /* wait for buffers to empty    */
  194.      FreeMem(PD->pd_PrintBuf,BUFSIZE*2);     /* free print buffer's memory   */
  195.      return(err); /* return status */
  196.      break;
  197.  
  198.     case 5 :   /* io_special flags call, density selection */
  199.      /* Centre the image? */
  200.      center = (x & SPECIAL_CENTER);  /* set center flag */
  201.  
  202.      /* select 72 or 96 lpi if DRAFT or NLQ selected */
  203.      if (PD->pd_Preferences.PrintQuality == DRAFT)
  204.        lpi = 72;
  205.      else
  206.        lpi = 96;
  207.      PED->ped_YDotsInch = (UWORD) lpi;
  208.      return(0);
  209.      break;
  210.  
  211.     default: 
  212.      return(0);
  213.      break;
  214.     }
  215. }
  216. /*****************  End of File: ColourJet/Render.c  *********************/
  217.  
  218.